function X = fft_custom(x)
    N = length(x);
    % Calculate the smallest power of 2 greater than or equal to N
    M = 2^(nextpow2(N));
    x_padded = [x, zeros(1, M - N)];  % Zero-pad the input signal
    if M <= 1
        X = x_padded;
        return;
    end
    % Recursively compute FFT for even and odd parts
    X_even = fft_custom(x_padded(1:2:end));
    X_odd = fft_custom(x_padded(2:2:end));
    % Precompute the twiddle factors (complex exponential terms)
    T = exp(-1i * 2 * pi * (0:(M/2-1)) / M);
    % Combine even and odd parts
    X = [X_even + T .* X_odd, X_even - T .* X_odd];
end
